﻿using System;
using System.Web;
using System.Xml;
using Framework.Library.Base.Base;

namespace Framework.Library.Base.Helper
{
    public class CredentialHelper : BaseClass
    {
        public static bool IsValidCredential(string ip)
        {
            if (cfg.CheckIP.VALUE.Equals(Boolean.TrueString, StringComparison.CurrentCultureIgnoreCase))
            {
                if (ip == "::1")
                    ip = "127.0.0.1";
                var doc = new XmlDocument();
                doc.Load(HttpContext.Current.Server.MapPath(cfg.LicencePath.VALUE));
                XmlNodeList nodeList = doc.SelectNodes("//licence");
                if (nodeList != null)
                {
                    for (int i = 0; i < nodeList.Count; i++)
                    {
                        XmlNodeList nodeIp = nodeList.Item(i).ChildNodes;
                        if (ip.Equals(nodeIp.Item(0).InnerText))
                            return true;
                    }
                }
            }
            else
                return true;
            return false;
        }
    }
}